/*
 * BinPackingView.java
 */
package binpacking.mvc.view;

import java.awt.Font;

import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;

import binpacking.mvc.controller.BinPackingViewController;
import binpacking.mvc.model.StartStateProperties;
import binpacking.mvc.model.TetrisBoard;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.JDialog;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;

/**
 * The application's main frame.
 */
public class BinPackingView extends FrameView {

	private javax.swing.JLabel boardHeight;
	private javax.swing.JLabel boardWidth;
	private javax.swing.JLabel iIcon;
	private static javax.swing.JPanel informationPanel;
	private javax.swing.JLabel jIcon;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JLabel lIcon;
	private javax.swing.JPanel mainPanel;
	private javax.swing.JMenuBar menuBar;
	private static TetrisBoardView tetrisBoardView;
	/**
         *
         */
	public static javax.swing.JTextField boardHeightTextField;
	/**
         *
         */
	public static javax.swing.JTextField boardWidthTextField;
	/**
         *
         */
	public static javax.swing.JTextField numIsTextField;
	/**
         *
         */
	public static javax.swing.JTextField numJsTextField;
	/**
         *
         */
	public static javax.swing.JTextField numLsTextField;
	/**
         *
         */
	public static javax.swing.JTextField numOsTextField;
	/**
         *
         */
	public static javax.swing.JTextField numSsTextField;
	/**
         *
         */
	public static javax.swing.JTextField numTsTextField;
	/**
         *
         */
	public static javax.swing.JTextField numZsTextField;
	private javax.swing.JLabel oIcon;
	/**
         *
         */
	public static javax.swing.JTextPane output;
	private javax.swing.JButton randomStateButton;
	private javax.swing.JLabel sIcon;
	/**
         *
         */
	public static javax.swing.JComboBox searchAlgorithmCombo;
	private javax.swing.JPanel settingsPanel;
	private javax.swing.JButton startSearchButton;
	private javax.swing.JButton stopSearchButton;
	private javax.swing.JLabel tIcon;
	private static javax.swing.JPanel visualizationPanel;
	private javax.swing.JLabel zIcon;
	private JMenu mnAbout;
	private JMenuItem mntmAboutBinPacker;

	/**
	 * 
	 * @param app
	 */
	public BinPackingView(SingleFrameApplication app) {
		super(app);
		getFrame().setTitle("Bin Packing App");

		initComponents();
		tetrisBoardView = new TetrisBoardView(new TetrisBoard(
				StartStateProperties.BOARD_WIDTH,
				StartStateProperties.BOARD_HEIGHT));
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	private void initComponents() {

		mainPanel = new javax.swing.JPanel();
		settingsPanel = new javax.swing.JPanel();
		oIcon = new javax.swing.JLabel();
		zIcon = new javax.swing.JLabel();
		jIcon = new javax.swing.JLabel();
		tIcon = new javax.swing.JLabel();
		lIcon = new javax.swing.JLabel();
		sIcon = new javax.swing.JLabel();
		iIcon = new javax.swing.JLabel();
		boardWidth = new javax.swing.JLabel();
		boardHeight = new javax.swing.JLabel();
		numOsTextField = new javax.swing.JTextField();
		numZsTextField = new javax.swing.JTextField();
		numJsTextField = new javax.swing.JTextField();
		numTsTextField = new javax.swing.JTextField();
		numLsTextField = new javax.swing.JTextField();
		numSsTextField = new javax.swing.JTextField();
		numIsTextField = new javax.swing.JTextField();
		boardWidthTextField = new javax.swing.JTextField();
		boardHeightTextField = new javax.swing.JTextField();
		randomStateButton = new javax.swing.JButton();
		searchAlgorithmCombo = new javax.swing.JComboBox();
		startSearchButton = new javax.swing.JButton();
		stopSearchButton = new javax.swing.JButton();
		visualizationPanel = new javax.swing.JPanel();
		informationPanel = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		output = new javax.swing.JTextPane();
		menuBar = new javax.swing.JMenuBar();
		javax.swing.JMenu fileMenu = new javax.swing.JMenu();
		javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
		exitMenuItem.setText("Exit");

		mainPanel.setName("mainPanel"); // NOI18N

		org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application
				.getInstance(binpacking.mvc.controller.main.BinPackingApp.class)
				.getContext().getResourceMap(BinPackingView.class);
		settingsPanel.setBorder(javax.swing.BorderFactory
				.createTitledBorder(resourceMap
						.getString("settingsPanel.border.title"))); // NOI18N
		settingsPanel.setName("settingsPanel"); // NOI18N

		oIcon.setIcon(new ImageIcon(
				BinPackingView.class
						.getResource("/binpacking/mvc/view/resources/39px-Tetromino_O.svg.png"))); // NOI18N
		oIcon.setText(resourceMap.getString("oIcon.text")); // NOI18N
		oIcon.setName("oIcon"); // NOI18N

		zIcon.setIcon(new ImageIcon(
				BinPackingView.class
						.getResource("/binpacking/mvc/view/resources/53px-Tetromino_Z.svg.png"))); // NOI18N
		zIcon.setText(resourceMap.getString("zIcon.text")); // NOI18N
		zIcon.setName("zIcon"); // NOI18N

		jIcon.setIcon(new ImageIcon(
				BinPackingView.class
						.getResource("/binpacking/mvc/view/resources/54px-Tetromino_J.svg.png"))); // NOI18N
		jIcon.setText(resourceMap.getString("jIcon.text")); // NOI18N
		jIcon.setName("jIcon"); // NOI18N

		tIcon.setIcon(new ImageIcon(
				BinPackingView.class
						.getResource("/binpacking/mvc/view/resources/54px-Tetromino_T.svg.png"))); // NOI18N
		tIcon.setText(resourceMap.getString("tIcon.text")); // NOI18N
		tIcon.setName("tIcon"); // NOI18N

		lIcon.setIcon(new ImageIcon(
				BinPackingView.class
						.getResource("/binpacking/mvc/view/resources/56px-Tetromino_L.svg.png"))); // NOI18N
		lIcon.setText(resourceMap.getString("lIcon.text")); // NOI18N
		lIcon.setName("lIcon"); // NOI18N

		sIcon.setIcon(new ImageIcon(
				BinPackingView.class
						.getResource("/binpacking/mvc/view/resources/56px-Tetromino_S.svg.png"))); // NOI18N
		sIcon.setText(resourceMap.getString("sIcon.text")); // NOI18N
		sIcon.setName("sIcon"); // NOI18N

		iIcon.setIcon(new ImageIcon(
				BinPackingView.class
						.getResource("/binpacking/mvc/view/resources/71px-Tetromino_I.svg.png"))); // NOI18N
		iIcon.setText(resourceMap.getString("iIcon.text")); // NOI18N
		iIcon.setName("iIcon"); // NOI18N
		boardWidth.setText("Bin Width"); // NOI18N
		boardHeight.setText("Bin Height"); // NOI18N

		numOsTextField.setText(String.valueOf(StartStateProperties.numOs)); // NOI18N
		numOsTextField.setName("numOsTextField"); // NOI18N

		numZsTextField.setText(String.valueOf(StartStateProperties.numZs)); // NOI18N
		numZsTextField.setName("numZsTextField"); // NOI18N

		numJsTextField.setText(String.valueOf(StartStateProperties.numJs)); // NOI18N
		numJsTextField.setName("numJsTextField"); // NOI18N

		numTsTextField.setText(String.valueOf(StartStateProperties.numTs)); // NOI18N
		numTsTextField.setName("numTsTextField"); // NOI18N

		numLsTextField.setText(String.valueOf(StartStateProperties.numLs)); // NOI18N
		numLsTextField.setName("numLsTextField"); // NOI18N

		numSsTextField.setText(String.valueOf(StartStateProperties.numSs)); // NOI18N
		numSsTextField.setName("numSsTextField"); // NOI18N

		numIsTextField.setText(String.valueOf(StartStateProperties.numIs)); // NOI18N
		numIsTextField.setName("numIsTextField"); // NOI18N
		boardWidthTextField.setText(String
				.valueOf(StartStateProperties.BOARD_WIDTH)); // NOI18N
		boardHeightTextField.setText(String
				.valueOf(StartStateProperties.BOARD_HEIGHT)); // NOI18N

		randomStateButton.setText("Random State"); // NOI18N
		randomStateButton.setName("randomStateButton"); // NOI18N
		randomStateButton
				.addActionListener(new java.awt.event.ActionListener() {
					@Override
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						BinPackingViewController
								.randomStateButtonActionPerformed(evt);
					}
				});

		searchAlgorithmCombo.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Depth FS", "Bredth FS", "Recursive DLS",
						"Iterative Deepening", "Simulated Annealing",
						"Hill Climbing", "A*", "Greedy Best First Search",
						"Genetic Algorithm", }));

		searchAlgorithmCombo.setName("searchAlgorithmCombo"); // NOI18N

		stopSearchButton.setText("stop search"); // NOI18N
		stopSearchButton.setName("stopSearchButton"); // NOI18N
		stopSearchButton.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				BinPackingViewController.stopSearchButtonActionPerformed(evt);
			}
		});

		startSearchButton.setText("Start Search"); // NOI18N
		startSearchButton.setName("startSearchButton"); // NOI18N
		startSearchButton
				.addActionListener(new java.awt.event.ActionListener() {
					@Override
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						BinPackingViewController
								.startSearchButtonActionPerformed(evt);
					}
				});

		javax.swing.GroupLayout gl_settingsPanel = new javax.swing.GroupLayout(
				settingsPanel);
		gl_settingsPanel
				.setHorizontalGroup(gl_settingsPanel
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_settingsPanel
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_settingsPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																searchAlgorithmCombo,
																0, 189,
																Short.MAX_VALUE)
														.addGroup(
																gl_settingsPanel
																		.createSequentialGroup()
																		.addGroup(
																				gl_settingsPanel
																						.createParallelGroup(
																								Alignment.LEADING)
																						.addComponent(
																								jIcon)
																						.addComponent(
																								sIcon)
																						.addComponent(
																								iIcon)
																						.addComponent(
																								oIcon)
																						.addComponent(
																								zIcon)
																						.addComponent(
																								tIcon)
																						.addComponent(
																								lIcon)
																						.addComponent(
																								boardWidth)
																						.addComponent(
																								boardHeight))
																		.addPreferredGap(
																				ComponentPlacement.RELATED)
																		.addGroup(
																				gl_settingsPanel
																						.createParallelGroup(
																								Alignment.LEADING)
																						.addComponent(
																								numOsTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								numIsTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								numJsTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								numTsTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								numLsTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								numSsTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								numZsTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								boardWidthTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE)
																						.addComponent(
																								boardHeightTextField,
																								GroupLayout.DEFAULT_SIZE,
																								36,
																								Short.MAX_VALUE))
																		.addGap(70))
														.addComponent(
																randomStateButton,
																GroupLayout.DEFAULT_SIZE,
																189,
																Short.MAX_VALUE)
														.addComponent(
																startSearchButton,
																GroupLayout.DEFAULT_SIZE,
																189,
																Short.MAX_VALUE)
														.addComponent(
																stopSearchButton,
																Alignment.TRAILING,
																GroupLayout.DEFAULT_SIZE,
																189,
																Short.MAX_VALUE))
										.addContainerGap()));
		gl_settingsPanel.setVerticalGroup(gl_settingsPanel.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_settingsPanel
						.createSequentialGroup()
						.addComponent(searchAlgorithmCombo,
								GroupLayout.PREFERRED_SIZE,
								GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addComponent(randomStateButton)
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(oIcon)
										.addComponent(numOsTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addGap(18)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(zIcon)
										.addComponent(numZsTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addGap(18)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(jIcon)
										.addComponent(numJsTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addGap(18)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(tIcon)
										.addComponent(numTsTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(lIcon)
										.addComponent(numLsTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addGap(18)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(numSsTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(sIcon))
						.addGap(18)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(iIcon)
										.addComponent(numIsTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addGap(18)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(boardWidth)
										.addComponent(boardWidthTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addGap(18)
						.addGroup(
								gl_settingsPanel
										.createParallelGroup(Alignment.LEADING)
										.addComponent(boardHeight)
										.addComponent(boardHeightTextField,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addComponent(startSearchButton)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(stopSearchButton)
						.addContainerGap(26, Short.MAX_VALUE)));
		settingsPanel.setLayout(gl_settingsPanel);

		visualizationPanel.setBorder(javax.swing.BorderFactory
				.createTitledBorder(resourceMap
						.getString("visualizationPanel.border.title"))); // NOI18N
		visualizationPanel.setName("visualizationPanel"); // NOI18N

		javax.swing.GroupLayout gl_visualizationPanel = new javax.swing.GroupLayout(
				visualizationPanel);
		visualizationPanel.setLayout(gl_visualizationPanel);
		gl_visualizationPanel.setHorizontalGroup(gl_visualizationPanel
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 313, Short.MAX_VALUE));
		gl_visualizationPanel.setVerticalGroup(gl_visualizationPanel
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 623, Short.MAX_VALUE));

		informationPanel.setBorder(javax.swing.BorderFactory
				.createTitledBorder(resourceMap
						.getString("informationPanel.border.title"))); // NOI18N
		informationPanel.setName("informationPanel"); // NOI18N

		jScrollPane1.setName("jScrollPane1"); // NOI18N

		output.setEditable(false);
		output.setName("output"); // NOI18N
		output.setFont(new Font("Monospaced", Font.PLAIN, 11));
		jScrollPane1.setViewportView(output);

		javax.swing.GroupLayout gl_informationPanel = new javax.swing.GroupLayout(
				informationPanel);
		informationPanel.setLayout(gl_informationPanel);
		gl_informationPanel.setHorizontalGroup(gl_informationPanel
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane1, 500, 600, Short.MAX_VALUE));
		gl_informationPanel.setVerticalGroup(gl_informationPanel
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane1,
						javax.swing.GroupLayout.DEFAULT_SIZE, 623,
						Short.MAX_VALUE));

		javax.swing.GroupLayout gl_mainPanel = new javax.swing.GroupLayout(
				mainPanel);
		gl_mainPanel.setHorizontalGroup(gl_mainPanel.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_mainPanel
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(settingsPanel,
								GroupLayout.PREFERRED_SIZE,
								GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(visualizationPanel,
								GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(informationPanel,
								GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
						.addGap(90)));
		gl_mainPanel
				.setVerticalGroup(gl_mainPanel
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								Alignment.TRAILING,
								gl_mainPanel
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_mainPanel
														.createParallelGroup(
																Alignment.TRAILING)
														.addComponent(
																informationPanel,
																Alignment.LEADING,
																GroupLayout.DEFAULT_SIZE,
																610,
																Short.MAX_VALUE)
														.addComponent(
																settingsPanel,
																Alignment.LEADING,
																GroupLayout.DEFAULT_SIZE,
																610,
																Short.MAX_VALUE)
														.addComponent(
																visualizationPanel,
																GroupLayout.DEFAULT_SIZE,
																610,
																Short.MAX_VALUE))
										.addContainerGap()));
		mainPanel.setLayout(gl_mainPanel);

		menuBar.setName("menuBar"); // NOI18N

		fileMenu.setText("File"); // NOI18N
		fileMenu.setName("fileMenu"); // NOI18N

		javax.swing.ActionMap actionMap = org.jdesktop.application.Application
				.getInstance(binpacking.mvc.controller.main.BinPackingApp.class)
				.getContext().getActionMap(BinPackingView.class, this);
		exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
		exitMenuItem.setName("exitMenuItem"); // NOI18N
		fileMenu.add(exitMenuItem);

		menuBar.add(fileMenu);

		setComponent(mainPanel);
		setMenuBar(menuBar);

		mnAbout = new JMenu();
		mnAbout.setText("About");
		mnAbout.setName("fileMenu");
		menuBar.add(mnAbout);

		mntmAboutBinPacker = new JMenuItem();
		mntmAboutBinPacker.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JDialog about = new AboutDialog();
				about.setVisible(true);
			}
		});
		mntmAboutBinPacker.setText("About Bin Packer");
		mntmAboutBinPacker.setName("exitMenuItem");
		mnAbout.add(mntmAboutBinPacker);
	}// </editor-fold>

	/**
	 * 
	 * @return
	 */
	public static javax.swing.JPanel getVisualizationPanel() {
		return visualizationPanel;
	}

	/**
	 * 
	 * @return
	 */
	public javax.swing.JTextField getNumIsTextField() {
		return numIsTextField;
	}

	/**
	 * 
	 * @return
	 */
	public javax.swing.JTextField getNumJsTextField() {
		return numJsTextField;
	}

	/**
	 * 
	 * @return
	 */
	public javax.swing.JTextField getNumLsTextField() {
		return numLsTextField;
	}

	/**
	 * 
	 * @return
	 */
	public javax.swing.JTextField getNumOsTextField() {
		return numOsTextField;
	}

	/**
	 * 
	 * @return
	 */
	public javax.swing.JTextField getNumSsTextField() {
		return numSsTextField;
	}

	/**
	 * 
	 * @return
	 */
	public javax.swing.JTextField getNumTsTextField() {
		return numTsTextField;
	}

	/**
	 * 
	 * @return
	 */
	public javax.swing.JTextField getNumZsTextField() {
		return numZsTextField;
	}

	public static void setTetrisBoardView(TetrisBoardView tetrisBoardView) {
		BinPackingView.tetrisBoardView = tetrisBoardView;
	}

	public static TetrisBoardView getTetrisBoardView() {
		return tetrisBoardView;
	}

}
